<template>
  <view class="my-userinfo-container">
    <!-- 头像昵称区域 -->
    <view class="top-box"  >
      <button  class="avatar-wrapper" open-type="chooseAvatar" @chooseavatar="onChooseAvatar" >
        <image class="avatar" :src="user?Img:userinfo.avatarUrl"></image>
      </button> 
      <input class="nickname" v-model="name" type="nickname"  @blur="saveName" ref="over" />
    </view>

    <!-- 面版列表区域 -->
    <view class="panel-list">
      <!-- 第一个面板 -->
      <view class="panel1">
        <view class="panel1-body">
          <view class="panel1-item1">
            <text>8</text>
            <text>收藏的店铺</text>
          </view>
          <view class="panel1-item1">
            <text>14</text>
            <text>收藏的商品</text>
          </view>
          <view class="panel1-item1">
            <text>18</text>
            <text>关注的商品</text>
          </view>
          <view class="panel1-item1">
            <text>84</text>
            <text>足迹</text>
          </view>
        </view>
      </view>
     <!-- 第二个面板 -->
      <view class="panel2">
        <view class="panel2-title">
          我的订单
        </view>
        <view class="panel2-body">
          <view class="panel2-item">
            <image src="/static//my-icons/icon1.png" mode=""></image>
            <text>待付款</text>
          </view>
          <view class="panel2-item">
            <image src="/static//my-icons/icon2.png" mode=""></image>
            <text>待收货</text>
          </view>
          <view class="panel2-item">
            <image src="/static//my-icons/icon3.png" mode=""></image>
            <text>退款/退货</text>
          </view>
          <view class="panel2-item">
            <image src="/static//my-icons/icon4.png" mode=""></image>
            <text>全部订单</text>
          </view>
        </view>
      </view>
      <!-- 第三个面板 -->
      <view class="panel3">
        <view class="panel-body">
          <view class="panel-item">
            <text>收获地址</text>
            <uni-icons type="right"></uni-icons>
          </view>
          <view class="panel-item">
            <text>联系客服</text>
            <uni-icons type="right"></uni-icons>
          </view>
          <view class="panel-item" @click="logout">
            <text>退出登录</text>
            <uni-icons type="right"></uni-icons>
          </view>
        </view>
      </view>
   </view>
      
  </view>
</template>

<script>
  import {mapState,mapMutations} from 'vuex'
  export default {
    name:"my-userinfo",
    
    data() {
      return {
        Img: JSON.parse(uni.getStorageSync('user')).img||
'',
        name: JSON.parse(uni.getStorageSync('user')).name||'微信用户',
        avatar:true,
        
      };
    },
    computed:{
      ...mapState('m_user',['userinfo','user'])
    },
    methods:{
      ...mapMutations('m_user',['updateToken','updateUserInfo','updateAddress','updataUser']),
      logout(){
        uni.showModal({
          title:'提示',
          content:'确认退出登录吗？',
          success:(res)=> {
            // 点击确认
            if(res.confirm==true){
              this.updateAddress({})
              this.updateToken('')
              this.updateUserInfo({})
              this.updataUser({})
            }
          }
        })
        
      },
      onChooseAvatar(e){
        this.Img = e.detail.avatarUrl
      },
      saveName(e){
        this.$nextTick(()=>{
          const obj = {
            img:this.Img,
            name:e.detail.value
          }
          this.updataUser(obj)
        })
      }
    }
  }
</script>

<style lang="scss">
.my-userinfo-container {
  height: 100%;
  // 为整个组件的结构添加浅灰色的背景
  background-color: #f4f4f4;

  .top-box {
    height: 400rpx;
    background-color: #c00000;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    .avatar-wrapper{
      background-color: #c00000;
      border-color: #c00000;
    }
    .avatar {
      display: block;
      width: 90px;
      height: 90px;
      border-radius: 45px;
      border: 2px solid white;
      box-shadow: 0 1px 5px black;
    }

    .nickname {
      color: white;
      font-weight: bold;
      font-size: 16px;
      margin-top: 10px;
      margin-left: 145px;
    }
  }
}
.panel-list{
  font-size: 12px;
  width: 95%;
  margin: 0 auto;
  .panel1,.panel2,.panel3{
    margin-top: 8px;
    border-radius: 6px;
    background-color: #ffffff;
  }
  .panel1{
    .panel1-body{
      height: 50px;
      display: flex;
      justify-content: space-around;
      .panel1-item1{
        display: flex;
        flex-direction: column;
        justify-content: center;
        align-items: center;
      }
    }
  }
  .panel2{
    .panel2-title{
      font-size: 14px;
      padding: 10px 0 10px 8px;
      border-bottom: 1px solid #efefef;
      // margin-bottom: 15px;
    }
    .panel2-body{
      display: flex;
      // align-items: center;
      justify-content: space-around;
      .panel2-item{
        display: flex;
        flex-direction: column;
        justify-content: center;
        align-item:center;
        margin:25px 0;
        image{
          width: 30px;
          height: 30px;
          display: block;
          margin: 0 auto;
        }
      }
    }
  }
  .panel3{
    .panel-body{
      // padding: 10px 0;
      .panel-item{
        padding: 10px 10px;
        display: flex;
        justify-content: space-between;
        align-items: center;
      }
    }
  }
}
</style>